import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // 自定义高亮css样式类名
  linkActiveClass: 'active', // 配置模糊匹配类名
  linkExactActiveClass: 'exact-active', // 配置精确匹配类名
  routes: [
    // 首页
    {
      path: '/',
      component: () => import('@/views/index/XuanIndexViews.vue')
    },

    // 文化
    {
      path: '/wenhua',
      component: () => import('@/views/wenhua/XuanWenHuaViews.vue')
    },
    {
      path: '/wenhua/yinyang',
      component: () => import('@/views/wenhua/XuanYinYangViews.vue')
    },
    {
      path: '/wenhua/wuxing',
      component: () => import('@/views/wenhua/XuanWuXingViews.vue')
    },
    {
      path: '/wenhua/tiangan',
      component: () => import('@/views/wenhua/XuanTianGanViews.vue')
    },
    {
      path: '/wenhua/dizhi',
      component: () => import('@/views/wenhua/XuanDiZhiViews.vue')
    },
    {
      path: '/wenhua/bagua',
      component: () => import('@/views/wenhua/XuanBaGuaViews.vue')
    },
    {
      path: '/wenhua/liushisigua',
      component: () => import('@/views/wenhua/XuanLiuShiSiGuaViews.vue')
    },
    {
      path: '/wenhua/bamen',
      component: () => import('@/views/wenhua/XuanBaMenViews.vue')
    },
    {
      path: '/wenhua/jiuxing',
      component: () => import('@/views/wenhua/XuanJiuXingViews.vue')
    },
    {
      path: '/wenhua/bashen',
      component: () => import('@/views/wenhua/XuanBaShenViews.vue')
    },
    {
      path: '/wenhua/shengxiao',
      component: () => import('@/views/wenhua/XuanShengXiaoViews.vue')
    },

    {
      path: '/wenhua/qimenjige',
      component: () => import('@/views/wenhua/XuanQiMenJiGeViews.vue')
    },
    {
      path: '/wenhua/qimenxiongge',
      component: () => import('@/views/wenhua/XuanQiMenXiongGeViews.vue')
    },

    // 工具
    {
      path: '/gongju',
      redirect: '/gongju/bazi', // 路由重定向
      component: () => import('@/views/gongju/XuanBaZiPaiPanViews.vue'),
    },
    {
      path: '/gongju/bazi',
      component: () => import('@/views/gongju/XuanBaZiPaiPanViews.vue')
    },
    {
      path: '/gongju/qimendunjia',
      component: () => import('@/views/gongju/XuanQiMenPaiPanViews.vue')
    },
    {
      path: '/gongju/liuyao',
      component: () => import('@/views/gongju/XuanLiuYaoPaiPanViews.vue')
    },
    {
      path: '/gongju/meihuayishu',
      component: () => import('@/views/gongju/XuanMeiHuaPaiPanViews.vue')
    },

    // 404
    {
      // path: '/:pathMatch(.*)',
      // path: '/:pathMatch(.*)*',
      path: '/:catchAll(.*)',
      component: () => import('@/views/404/XuanNotFindViews.vue')
    }
  ]
})

// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 将滚动位置重置为顶部
  window.scrollTo(0, 0);
  next(); // 跳转
})

// 全局解析守卫
router.beforeResolve((to, from, next) => {
  next(); // 跳转
})

// 全局后置守卫
router.afterEach((to, from) => {
  // // 判断路由跳转路径
  // if ((to.path === from.path) && ('/' !== from.path) && ('/wenhua' !== from.path)) {
  //   window.location.href = to.path // 刷新页面
  // } else {
  //   next(); // 跳转
  // }
  // next(); // 跳转
})

export default router
